package com.lw.yygh.hosp.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.lw.yygh.exception.YyghException;
import com.lw.yygh.hosp.service.HospSetService;
import com.lw.yygh.model.hosp.HospSet;
import com.lw.yygh.hosp.mapper.HospSetMapper;
import com.lw.yygh.model.order.SignInfoVo;
import com.lw.yygh.result.ResultCodeEnum;
import org.springframework.stereotype.Service;

@Service
public class HospSetServiceImpl extends ServiceImpl<HospSetMapper, HospSet> implements HospSetService {
    @Override
    public String getSignKey(String hoscode) {
        HospSet hospSet = baseMapper.selectOne( new QueryWrapper<HospSet>().eq( "hoscode", hoscode ) );
        return hospSet.getSignKey();
    }

    @Override
    public SignInfoVo getSignInfoVo(String hoscode) {
        QueryWrapper<HospSet> wrapper = new QueryWrapper<>();
        wrapper.eq("hoscode",hoscode);
        HospSet hospitalSet = baseMapper.selectOne(wrapper);
        if(null == hospitalSet) {
            throw new YyghException( ResultCodeEnum.HOSPITAL_OPEN);
        }
        SignInfoVo signInfoVo = new SignInfoVo();
        signInfoVo.setApiUrl(hospitalSet.getApiUrl());
        signInfoVo.setSignKey(hospitalSet.getSignKey());
        return signInfoVo;

    }
}
